<template>
    <div class="index"></div>
</template>
<script setup lang="ts">
    import { onMounted, reactive } from 'vue'
    import { login, getInfo, logout } from '@/api/user'
    import { setToken, setExpiresIn, getOpenId, setOpenId  } from '@/utils/auth'
    import { setLocalStorage, getLocalStorage } from '@/utils/localStorage'
    import { useRoute, useRouter } from 'vue-router'

    const router = useRouter()
    const loginData = reactive({
        userName:'',
        password:'',
    })

    onMounted(() => {
        if(import.meta.env.MODE === 'development') {
            logout().then(() => {
                login(loginData).then((res: any) => {
                    const data1 = res.data
                    setToken(data1.access_token)
                    setExpiresIn(data1.expires_in)
                    getInfo().then((res:any) => {
                        setLocalStorage('userInfo',{
                            userName: res.user.userName,
                            avatar: res.user.avatar,
                            nickName: res.user.nickName,
                            shopName: res.user.shopName,
                            shopId:res.user.shopId,
                            issh:res.user.issh,
                        })
                    })
                    router.replace({path:'/userCenter'})  
                })
            }) 
            
        } else {
           router.push({path:'/404'})  
        }
    })

</script>
    